<?php

	$id = $_REQUEST['id'];
	$rank = $_REQUEST['rank'];
	$url = "http://ecat-dev.gbif.org/ws/nav/";

	switch( strtolower($rank) ) {
		case '':
			$rank = 'k';
			break;
		case 'k':
		case 'kingdom':
			$rank = 'p';
			break;
		case 'p':
		case 'phylum':
			$rank = 'c';
			break;
		case 'c':
		case 'class':
			$rank = 'o';
			break;
		case 'o':
		case 'order':
			$rank = 'f';
			break;
		case 'f':
		case 'family':
			$rank = 's';
			break;
	}

	$json = file_get_contents($url . "?sort=alpha&rank=$rank&id=" . $id); 
	header('Content-type: application/json charset=utf-8');
	print $json;

?>